#!/bin/sh

# Remove the hook from /etc/profile
start_line=`grep -n "BEGIN TPKG" /etc/profile | awk -F: '{print $1}'`
end_line=`grep -n "END TPKG" /etc/profile | awk -F: '{print $1}'`
# Check that we actually got valid start and end line
if [ $start_line ] && [ $end_line ] && [ $start_line -lt $end_line ]
then
  tmpfile=`mktemp -t etc.profile.XXXXXX`
  # yank out those lines
  sed -e "$start_line,$end_line d" /etc/profile > $tmpfile
  chmod 644 $tmpfile
  if [ -s $tmpfile ]; then
    mv $tmpfile /etc/profile
  fi
fi
